package com.lkd.handler;

import com.lkd.business.MsgHandler;
import com.lkd.config.TopicConfig;
import com.lkd.contract.SupplyContract;
import com.lkd.emq.Topic;
import com.lkd.service.VendingMachineService;
import com.lkd.utils.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;


@Component
@Topic(TopicConfig.VMS_SUPPLY_TOPIC) // 补货工单主题
@Slf4j
public class SupplyMsgHandler implements MsgHandler {

    @Autowired
    private VendingMachineService vendingMachineService;

    @Override
    public void process(String jsonMsg) throws IOException {
        log.info("收到补货工单消息,更新售货机状态,更新售货机库存");
        // 解析消息内容
        SupplyContract supplyContract = JsonUtil.getByJson(jsonMsg, SupplyContract.class);
        // 更新说伙计状态
        vendingMachineService.updateVMBuHuo(supplyContract);

    }
}
